package org.qhhc.bionioaio.nio.client;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class UserInputHandler implements Runnable{
    private ChatClient chatClient;

    public  UserInputHandler(org.qhhc.bionioaio.nio.client.ChatClient chatClient){
        this.chatClient=chatClient;
    }

    @Override
    public void run() {
        BufferedReader consoleReader =new BufferedReader(new InputStreamReader(System.in));
        while (true){
            try {
                String msg =consoleReader.readLine();
                chatClient.send(msg);
                if (chatClient.readyToQuit(msg)) break;

            }catch (Exception e){
                e.printStackTrace();
            }
        }

    }
}
